package cn.jltx.rxjava.rx.api;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2017/08/16.
 */

public class TencentService {

    static Retrofit retrofit = new Retrofit.Builder().baseUrl("http://sportsnba.qq.com/")
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(getOkHttpClient()).build();
    static TencentApi api = retrofit.create(TencentApi.class);

    public static OkHttpClient getOkHttpClient(){
        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .connectTimeout(20 * 1000, TimeUnit.MILLISECONDS)
                .readTimeout(20 * 1000, TimeUnit.MILLISECONDS)
                .retryOnConnectionFailure(true); // 失败重发
        return builder.build();
    }

    public static TencentApi getApi() {
        return api;
    }
}
